home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 414_01 / COMMSOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-21  |  43.3 KB  |  1,479 lines

  1. /***********************************************************************/
  2. /* COMMSOS.C - sos commands.                                           */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1993 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Header: C:\THE\RCS\commsos.c 1.4 1993/09/01 16:25:56 MH Interim MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /*#define DEBUG 1*/
  51.  
  52. /*man-start*********************************************************************
  53.  
  54.  
  55.  
  56. ========================================================================
  57. SOS COMMAND REFERENCE
  58. ========================================================================
  59. **man-end**********************************************************************/
  60.  
  61. /*-------------------------- external data ----------------------------*/
  62. extern LINE *first_command,*current_command,*last_command;
  63. extern LINE *next_line,*curr_line;
  64. extern VIEW_DETAILS *vd_current,*vd_first;
  65. extern char current_screen;
  66. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  67. extern char current_file;         /* pointer to current file */
  68. extern WINDOW *foot,*error_window;
  69. extern bool error_on_screen;
  70. extern char *rec;
  71. extern unsigned short rec_len;
  72. extern char *cmd_rec;
  73. extern unsigned short cmd_rec_len;
  74. extern char *pre_rec;
  75. extern unsigned short pre_rec_len;
  76. extern char mode_insert;        /* defines insert mode toggle */
  77. extern char in_profile;    /* indicates if processing profile */
  78. extern unsigned short file_start;
  79.  
  80. extern char *temp_cmd;
  81. extern char dir_filename[10];
  82. extern char dir_pathname[MAX_FILE_NAME+1];
  83. extern char sp_path[MAX_FILE_NAME+1] ;
  84. extern char sp_fname[MAX_FILE_NAME+1] ;
  85. extern char dir_path[MAX_FILE_NAME+1] ;    /* for dir and ls commands */
  86. extern bool prefix_changed;
  87. /*man-start*********************************************************************
  88. COMMAND
  89.      SOS ADDline - add blank line after focus line
  90.      SOS LINEAdd - add blank line after focus line
  91.  
  92. SYNTAX
  93.      ** effective only if bound to a key **
  94.  
  95. DESCRIPTION
  96.      The SOS ADDLINE command inserts a blank line in the file following
  97.      the focus line. The cursor is placed in the column under the first
  98.      non-blank in the focus line.
  99.  
  100. COMPATIBILITY
  101.      XEDIT: Compatible.
  102.      KEDIT: Compatible.
  103.  
  104. SEE ALSO
  105.      SOS DELLINE
  106.  
  107. STATUS
  108.      Complete
  109. **man-end**********************************************************************/
  110. #ifdef PROTO
  111. int Sos_addline(char *params)
  112. #else
  113. int Sos_addline(params)
  114. char *params;
  115. #endif
  116. /***********************************************************************/
  117. {
  118. /*--------------------------- local data ------------------------------*/
  119.  short rc;
  120. /*--------------------------- processing ------------------------------*/
  121. #ifdef TRACE
  122.  trace_function("commsos.c: Sos_addline");
  123. #endif
  124.  rc = Add("1");
  125. #ifdef TRACE
  126.  trace_return();
  127. #endif
  128.  return(rc);
  129. }
  130. /*man-start*********************************************************************
  131. COMMAND
  132.      SOS CURSORAdj - move first non-blank character to cursor
  133.  
  134. SYNTAX
  135.      ** effective only if bound to a key **
  136.  
  137. DESCRIPTION
  138.      The SOS CURSORADJ command moves text in the focus line so that
  139.      the first non-blank character appears under the cursor position.
  140.  
  141. COMPATIBILITY
  142.      XEDIT: N/A
  143.      KEDIT: Compatible.
  144.  
  145. STATUS
  146.      Complete
  147. **man-end**********************************************************************/
  148. #ifdef PROTO
  149. int Sos_cursoradj(char *params)
  150. #else
  151. int Sos_cursoradj(params)
  152. char *params;
  153. #endif
  154. /***********************************************************************/
  155. {
  156. /*--------------------------- local data ------------------------------*/
  157.  short num_cols,first_non_blank_col,col,rc;
  158.  unsigned short x,y;
  159. /*--------------------------- processing ------------------------------*/
  160. #ifdef TRACE
  161.  trace_function("commsos.c: Sos_cursoradj");
  162. #endif
  163.  getyx(CURRENT_WINDOW,y,x);
  164.  switch (CURRENT_VIEW->current_window)
  165.    {
  166.     case WINDOW_MAIN:
  167.          if (FOCUS_TOF || FOCUS_BOF)
  168.            {
  169.             display_error(38,(char *)"");
  170. #ifdef TRACE
  171.             trace_return();
  172. #endif
  173.             return(RC_INVALID_ENVIRON);
  174.            }
  175.          col = x + CURRENT_VIEW->verify_col - 1;
  176.          first_non_blank_col = strzne(rec,' ');
  177.          if (first_non_blank_col == (-1))
  178.             first_non_blank_col = 0;
  179.          num_cols = first_non_blank_col - col;
  180.          if (num_cols < 0)
  181.             rc = execute_shift_command(FALSE,-num_cols,CURRENT_VIEW->focus_line,1);
  182.          else
  183.             if (num_cols > 0)
  184.                rc = execute_shift_command(TRUE,num_cols,CURRENT_VIEW->focus_line,1);
  185.          break;
  186.     default:
  187.          break;
  188.    }
  189. #ifdef TRACE
  190.  trace_return();
  191. #endif
  192.  return(rc);
  193. }
  194. /*man-start*********************************************************************
  195. COMMAND
  196.      SOS DELBAck - delete the character to the left of the cursor
  197.  
  198. SYNTAX
  199.      ** effective only if bound to a key **
  200.  
  201. DESCRIPTION
  202.      The SOS DELBACK command moves the cursor one character to the left
  203.      and deletes the character now under the cursor.
  204.  
  205. COMPATIBILITY
  206.      XEDIT: N/A
  207.      KEDIT: Compatible.
  208.  
  209. SEE ALSO
  210.      SOS DELCHAR
  211.  
  212. STATUS
  213.      Complete
  214. **man-end**********************************************************************/
  215. #ifdef PROTO
  216. int Sos_delback(char *params)
  217. #else
  218. int Sos_delback(params)
  219. char *params;
  220. #endif
  221. /***********************************************************************/
  222. {
  223. /*------------------------- external data -----------------------------*/
  224.  extern bool extended_display_mode;
  225.  extern bool CMDARROWSTABLRx;
  226. /*--------------------------- local data ------------------------------*/
  227.  unsigned short x,y;
  228.  bool save_CMDARROWSTABLRx = CMDARROWSTABLRx;
  229. /*--------------------------- processing ------------------------------*/
  230. #ifdef TRACE
  231.  trace_function("commsos.c: Sos_delback");
  232. #endif
  233.  getyx(CURRENT_WINDOW,y,x);
  234.  switch (CURRENT_VIEW->current_window)
  235.    {
  236.     case WINDOW_MAIN:
  237.          if (FOCUS_TOF || FOCUS_BOF)
  238.            {
  239.             display_error(38,(char *)"");
  240. #ifdef TRACE
  241.             trace_return();
  242. #endif
  243.             return(RC_INVALID_ENVIRON);
  244.            }
  245.          break;
  246.     case WINDOW_COMMAND:
  247.          if (x == 0)
  248.            {
  249. #ifdef TRACE
  250.             trace_return();
  251. #endif
  252.             return(RC_OK);
  253.            }
  254.          mvwdelch(CURRENT_WINDOW,y,x-1);
  255.          if (x <= cmd_rec_len)
  256.            {
  257.             cmd_rec = (char *)memdelchr((char *)cmd_rec,
  258.                                                x-1,cmd_rec_len,1);
  259.             cmd_rec_len--;
  260.            }
  261. #ifdef TRACE
  262.          trace_return();
  263. #endif
  264.          return(RC_OK);
  265.          break;
  266.     case WINDOW_PREFIX:
  267.          if (x == 0)
  268.            {
  269. #ifdef TRACE
  270.             trace_return();
  271. #endif
  272.             return(RC_OK);
  273.            }
  274.          prefix_changed = TRUE;
  275.          mvwdelch(CURRENT_WINDOW,y,x-1);
  276.          if (x <= pre_rec_len)
  277.            {
  278.             pre_rec = (char *)memdelchr((char *)pre_rec,
  279.                                                x-1,pre_rec_len,1);
  280.             pre_rec_len--;
  281.            }
  282. #ifdef TRACE
  283.             trace_return();
  284. #endif
  285.          return(RC_OK);
  286.          break;
  287.     default:
  288.          break;
  289.    }
  290. /*---------------------------------------------------------------------*/
  291. /* Remainder of processing is only for WINDOW_MAIN.                    */
  292. /*---------------------------------------------------------------------*/
  293.  if (x == 0 && CURRENT_VIEW->verify_start == CURRENT_VIEW->verify_col)
  294.    {
  295. #ifdef TRACE
  296.     trace_return();
  297. #endif
  298.     return(RC_OK);
  299.    }
  300.  CMDARROWSTABLRx = FALSE;
  301.  Left_arrow("");
  302.  CMDARROWSTABLRx = save_CMDARROWSTABLRx;
  303. /*---------------------------------------------------------------------*/
  304. /* If we are after the last character of the line, exit.               */
  305. /*---------------------------------------------------------------------*/
  306.  if (x+CURRENT_VIEW->verify_col-1 > rec_len)
  307.    {
  308. #ifdef TRACE
  309.     trace_return();
  310. #endif
  311.     return(RC_OK);
  312.    }
  313.  
  314.  getyx(CURRENT_WINDOW,y,x);
  315.  mvwdelch(CURRENT_WINDOW,y,x);
  316.  
  317.  rec = (char *)memdelchr((char *)rec,CURRENT_VIEW->verify_col-1+x,rec_len,1);
  318.  rec_len--;
  319. /*---------------------------------------------------------------------*/
  320. /* If there is a character off the right edge of the screen, display it*/
  321. /* in the last character of the main window.                           */
  322. /*---------------------------------------------------------------------*/
  323.  if (CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1 < rec_len)
  324.    {
  325.     wmove(CURRENT_WINDOW,y,CURRENT_SCREEN.cols-1);
  326.     if (extended_display_mode)
  327.        waddch(CURRENT_WINDOW,rec[CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1]);
  328.     else
  329.        put_char(CURRENT_WINDOW,
  330.              rec[CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1],ADDCHAR);
  331.     wmove(CURRENT_WINDOW,y,x);
  332.    }
  333. #ifdef TRACE
  334.  trace_return();
  335. #endif
  336.  return(RC_OK);
  337. }
  338. /*man-start*********************************************************************
  339. COMMAND
  340.      SOS DELChar - delete character under cursor
  341.  
  342. SYNTAX
  343.      ** effective only if bound to a key **
  344.  
  345. DESCRIPTION
  346.      The SOS DELCHAR command deletes the character under the cursor.
  347.      Text to the right is shifted to the left.
  348.  
  349. COMPATIBILITY
  350.      XEDIT: N/A
  351.      KEDIT: Compatible.
  352.  
  353. STATUS
  354.      Complete
  355. **man-end**********************************************************************/
  356. #ifdef PROTO
  357. int Sos_delchar(char *params)
  358. #else
  359. int Sos_delchar(params)
  360. char *params;
  361. #endif
  362. /***********************************************************************/
  363. {
  364. /*------------------------- external data -----------------------------*/
  365.  extern bool extended_display_mode;
  366. /*--------------------------- local data ------------------------------*/
  367.  unsigned short x,y;
  368. /*--------------------------- processing ------------------------------*/
  369. #ifdef TRACE
  370.  trace_function("commsos.c: Sos_delchar");
  371. #endif
  372. /*---------------------------------------------------------------------*/
  373. /* Do not allow this command on the top or bottom of file lines.       */
  374. /*---------------------------------------------------------------------*/
  375.  if (CURRENT_VIEW->current_window == WINDOW_MAIN
  376.  &&  (FOCUS_TOF || FOCUS_BOF))
  377.       {
  378.        display_error(38,(char *)"");
  379. #ifdef TRACE
  380.        trace_return();
  381. #endif
  382.        return(RC_INVALID_ENVIRON);
  383.       }
  384.  getyx(CURRENT_WINDOW,y,x);
  385.  wdelch(CURRENT_WINDOW);
  386.  switch (CURRENT_VIEW->current_window)
  387.    {
  388.     case WINDOW_COMMAND:
  389.          if (x < cmd_rec_len)
  390.            {
  391.             cmd_rec = (char *)memdelchr((char *)cmd_rec,
  392.                                                x,cmd_rec_len,1);
  393.             cmd_rec_len--;
  394.            }
  395. #ifdef TRACE
  396.          trace_return();
  397. #endif
  398.          return(RC_OK);
  399.          break;
  400.     case WINDOW_PREFIX:
  401.          if (x < pre_rec_len)
  402.            {
  403.             prefix_changed = TRUE;
  404.             pre_rec = (char *)memdelchr((char *)pre_rec,
  405.                                                x,pre_rec_len,1);
  406.             pre_rec_len--;
  407.            }
  408. #ifdef TRACE
  409.          trace_return();
  410. #endif
  411.          return(RC_OK);
  412.          break;
  413.     default:
  414.          break;
  415.    }
  416.  
  417. /*---------------------------------------------------------------------*/
  418. /* If we are after the last character of the line, exit.               */
  419. /*---------------------------------------------------------------------*/
  420.  if (x+CURRENT_VIEW->verify_col > rec_len)
  421.    {
  422. #ifdef TRACE
  423.     trace_return();
  424. #endif
  425.     return(RC_OK);
  426.    }
  427.  
  428.  rec = (char *)memdelchr((char *)rec,CURRENT_VIEW->verify_col-1+x,rec_len,1);
  429.  rec_len--;
  430. /*---------------------------------------------------------------------*/
  431. /* If there is a character off the right edge of the screen, display it*/
  432. /* in the last character of the main window.                           */
  433. /*---------------------------------------------------------------------*/
  434.  if (CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1 < rec_len)
  435.    {
  436.     wmove(CURRENT_WINDOW,y,CURRENT_SCREEN.cols-1);
  437.     if (extended_display_mode)
  438.        waddch(CURRENT_WINDOW,rec[CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1]);
  439.     else
  440.        put_char(CURRENT_WINDOW,
  441.              rec[CURRENT_VIEW->verify_col-1+CURRENT_SCREEN.cols-1],ADDCHAR);
  442.     wmove(CURRENT_WINDOW,y,x);
  443.    }
  444. #ifdef TRACE
  445.  trace_return();
  446. #endif
  447.  return(RC_OK);
  448. }
  449. /*man-start*********************************************************************
  450. COMMAND
  451.      SOS DELEnd - delete to end of line
  452.  
  453. SYNTAX
  454.      ** effective only if bound to a key **
  455.  
  456. DESCRIPTION
  457.      The SOS DELEND command deletes all characters from the current
  458.      column to the end of line.
  459.  
  460. COMPATIBILITY
  461.      XEDIT: N/A
  462.      KEDIT: Compatible.
  463.  
  464. STATUS
  465.      Complete.
  466. **man-end**********************************************************************/
  467. #ifdef PROTO
  468. int Sos_delend(char *params)
  469. #else
  470. int Sos_delend(params)
  471. char *params;
  472. #endif
  473. /***********************************************************************/
  474. {
  475. /*--------------------------- local data ------------------------------*/
  476.  register short i;
  477.  unsigned short col,x,y;
  478. /*--------------------------- processing ------------------------------*/
  479. #ifdef TRACE
  480.  trace_function("commsos.c: Sos_delend");
  481. #endif
  482.  getyx(CURRENT_WINDOW,y,x);
  483.  switch (CURRENT_VIEW->current_window)
  484.    {
  485.     case WINDOW_MAIN:
  486.          if (FOCUS_TOF || FOCUS_BOF)
  487.            {
  488.             display_error(38,(char *)"");
  489. #ifdef TRACE
  490.             trace_return();
  491. #endif
  492.             return(RC_INVALID_ENVIRON);
  493.            }
  494.          col = x + CURRENT_VIEW->verify_col - 1;
  495.          for (i=col;i<max_line_length;i++)
  496.              rec[i] = ' ';
  497.          if (rec_len > col)
  498.             rec_len = col;
  499.          break;
  500.     case WINDOW_COMMAND:
  501.          for (i=x;i<COLS;i++)
  502.              cmd_rec[i] = ' ';
  503.          if (cmd_rec_len > x)
  504.             cmd_rec_len = x;
  505.          break;
  506.     case WINDOW_PREFIX:
  507.          prefix_changed = TRUE;
  508.          for (i=x;i<PREFIX_WIDTH;i++)
  509.              pre_rec[i] = ' ';
  510.          if (pre_rec_len > x)
  511.             pre_rec_len = x;
  512.          break;
  513.     default:
  514.          break;
  515.    }
  516.  my_wclrtoeol(CURRENT_WINDOW);
  517. #ifdef TRACE
  518.  trace_return();
  519. #endif
  520.  return(RC_OK);
  521. }
  522. /*man-start*********************************************************************
  523. COMMAND
  524.      SOS DELLine - delete focus line
  525.      SOS LINEDel - delete focus line
  526.  
  527. SYNTAX
  528.      ** effective only if bound to a key **
  529.  
  530. DESCRIPTION
  531.      The SOS DELLINE command deletes the focus line.
  532.  
  533. COMPATIBILITY
  534.      XEDIT: Compatible.
  535.      KEDIT: Compatible.
  536.  
  537. SEE ALSO
  538.      SOS ADDLINE
  539.  
  540. STATUS
  541.      Complete
  542. **man-end**********************************************************************/
  543. #ifdef PROTO
  544. int Sos_delline(char *params)
  545. #else
  546. int Sos_delline(params)
  547. char *params;
  548. #endif
  549. /***********************************************************************/
  550. {
  551. /*--------------------------- local data ------------------------------*/
  552.  short rc;
  553. /*--------------------------- processing ------------------------------*/
  554. #ifdef TRACE
  555.  trace_function("commsos.c: Sos_delline");
  556. #endif
  557.  rc = DeleteLine("1");
  558. #ifdef TRACE
  559.  trace_return();
  560. #endif
  561.  return(rc);
  562. }
  563. /*man-start*********************************************************************
  564. COMMAND
  565.      SOS DELWord - delete word at or right of cursor
  566.  
  567. SYNTAX
  568.      ** effective only if bound to a key **
  569.  
  570. DESCRIPTION
  571.      The SOS DELWORD command deletes the word at or to the right
  572.      of the current cursor position.
  573.  
  574. COMPATIBILITY
  575.      XEDIT: N/A
  576.      KEDIT: Compatible.
  577.  
  578. STATUS
  579.      Complete
  580. **man-end**********************************************************************/
  581. #ifdef PROTO
  582. int Sos_delword(char *params)
  583. #else
  584. int Sos_delword(params)
  585. char *params;
  586. #endif
  587. /***********************************************************************/
  588. {
  589. #define FIRST_BLANK  0
  590. #define SECOND_BLANK 1
  591. #define FIRST_WORD   2
  592. #define SECOND_WORD  3
  593. /*--------------------------- local data ------------------------------*/
  594.  register short i;
  595.  short rc;
  596.  int state,cursor_off;
  597.  unsigned short x,y,temp_rec_len;
  598.  short num_cols,col,col_pos,rec_pos,left_col;
  599.  char *temp_rec;
  600. /*--------------------------- processing ------------------------------*/
  601. #ifdef TRACE
  602.  trace_function("commsos.c: Sos_delword");
  603. #endif
  604. /*---------------------------------------------------------------------*/
  605. /* This function is not applicable to the PREFIX window.               */
  606. /*---------------------------------------------------------------------*/
  607.  getyx(CURRENT_WINDOW,y,x);
  608.  switch(CURRENT_VIEW->current_window)
  609.    {
  610.     case WINDOW_PREFIX:
  611.          display_error(38,(char *)"");
  612. #ifdef TRACE
  613.          trace_return();
  614. #endif
  615.          return(RC_INVALID_ENVIRON);
  616.          break;
  617.     case WINDOW_MAIN:
  618.          temp_rec = rec;
  619.          temp_rec_len = rec_len;
  620.          left_col = CURRENT_VIEW->verify_col-1;
  621.          break;
  622.     case WINDOW_COMMAND:
  623.          temp_rec = cmd_rec;
  624.          temp_rec_len = cmd_rec_len;
  625.          left_col = 0;
  626.          break;
  627.    }
  628. /*---------------------------------------------------------------------*/
  629. /* If we are after the last column of the line, then just ignore the   */
  630. /* command and leave the cursor where it is.                           */
  631. /*---------------------------------------------------------------------*/
  632.  if ((x + left_col) >= temp_rec_len)
  633.    {
  634. #ifdef TRACE
  635.     trace_return();
  636. #endif
  637.     return(RC_OK);
  638.    }
  639. /*---------------------------------------------------------------------*/
  640. /* Determine the end   of the next word, or go to the end of the line  */
  641. /* if already at or past beginning of last word.                       */
  642. /*---------------------------------------------------------------------*/
  643.  cursor_off = num_cols = 0;
  644.  if (*(temp_rec+left_col+x) == ' ')
  645.     state = FIRST_BLANK;
  646.  else
  647.    {
  648.     state = FIRST_WORD;
  649.     for (i=left_col+x;;i--)
  650.       {
  651.        if (*(temp_rec+i) == ' '
  652.        ||  i == -1)
  653.          {
  654.           cursor_off++;
  655.           break;
  656.          }
  657.        cursor_off--;
  658.       }
  659.    }
  660.  for (i=left_col+x+cursor_off;i<temp_rec_len;i++)
  661.    {
  662.     switch(state)
  663.        {
  664.         case FIRST_BLANK:
  665.              if (*(temp_rec+i) != ' ')
  666.                 state = FIRST_WORD;
  667.              break;
  668.         case FIRST_WORD:
  669.              if (*(temp_rec+i) == ' ')
  670.                 state = SECOND_BLANK;
  671.              break;
  672.         case SECOND_BLANK:
  673.              if (*(temp_rec+i) != ' ')
  674.                 state = SECOND_WORD;
  675.              break;
  676.        }
  677.     if (state == SECOND_WORD)
  678.        break;
  679.     num_cols++;
  680.    }
  681. /*---------------------------------------------------------------------*/
  682. /* Delete from the field the number of columns calculated above        */
  683. /* and adjust the appropriate record length.                           */
  684. /*---------------------------------------------------------------------*/
  685.  temp_rec = memdelchr(temp_rec,left_col+x+cursor_off,temp_rec_len,num_cols);
  686.  switch(CURRENT_VIEW->current_window)
  687.    {
  688.     case WINDOW_MAIN:
  689.          rec_len -= num_cols;
  690. /*       post_process_line(CURRENT_VIEW->focus_line);*/
  691.          col_pos = x;
  692.          if ((col_pos+cursor_off) >= 0)
  693.            {
  694.             show_page();
  695.             wmove(CURRENT_WINDOW,y,x+cursor_off);
  696.            }
  697.          else
  698.            {
  699.             rec_pos = left_col + x + cursor_off;
  700.             x = CURRENT_SCREEN.cols / 2;
  701.             CURRENT_VIEW->verify_col = max(1,rec_pos - x + 2);
  702.             rec_pos = (CURRENT_VIEW->verify_col == 1) ? rec_pos : x - 1;
  703.             wmove(CURRENT_WINDOW,y,rec_pos);
  704.             show_page();
  705.            }
  706.          break;
  707.     case WINDOW_COMMAND:
  708.          cmd_rec_len -= num_cols;
  709.          wmove(CURRENT_WINDOW,y,x+cursor_off);
  710.          for (i=0;i<num_cols;i++)
  711.             wdelch(CURRENT_WINDOW);
  712.          break;
  713.    }
  714. #ifdef TRACE
  715.  trace_return();
  716. #endif
  717.  return(rc);
  718. }
  719. /*man-start*********************************************************************
  720. COMMAND
  721.      SOS DOPREfix - execute any pending prefix commands
  722.  
  723. SYNTAX
  724.      ** effective only if bound to a key **
  725.  
  726. DESCRIPTION
  727.      The SOS DOPREFIX command executes any pending prefix commands.
  728.  
  729. COMPATIBILITY
  730.      XEDIT: N/A
  731.      KEDIT: Compatible.
  732.  
  733. STATUS
  734.      Complete
  735. **man-end**********************************************************************/
  736. #ifdef PROTO
  737. int Sos_doprefix(char *params)
  738. #else
  739. int Sos_doprefix(params)
  740. char *params;
  741. #endif
  742. /***********************************************************************/
  743. {
  744. /*------------------------- external data -----------------------------*/
  745. /*--------------------------- local data ------------------------------*/
  746.  int rc;
  747. /*--------------------------- processing ------------------------------*/
  748. #ifdef TRACE
  749.  trace_function("commsos.c: Sos_doprefix");
  750. #endif
  751. /*---------------------------------------------------------------------*/
  752. /*                                                                     */
  753. /*---------------------------------------------------------------------*/
  754. /* post_process_line(CURRENT_VIEW->focus_line);*/
  755.  rc = execute_prefix_commands();
  756. #ifdef TRACE
  757.  trace_return();
  758. #endif
  759.  return(rc);
  760. }
  761. /*man-start*********************************************************************
  762. COMMAND
  763.      SOS EDIT - edit a file from directory list
  764.  
  765. SYNTAX
  766.      ** effective only if bound to a key **
  767.  
  768. DESCRIPTION
  769.      The SOS EDIT command allows the user to edit a file, chosen from
  770.      a directory list.(the file DIR.DIR).
  771.  
  772. COMPATIBILITY
  773.      XEDIT: N/A
  774.      KEDIT: Compatible with default definition for Alt-X key.
  775.  
  776. STATUS
  777.      Complete.
  778. **man-end**********************************************************************/
  779. #ifdef PROTO
  780. int Sos_edit(char *params)
  781. #else
  782. int Sos_edit(params)
  783. char *params;
  784. #endif
  785. /***********************************************************************/
  786. {
  787. /*--------------------------- local data ------------------------------*/
  788.  register short i,j;
  789.  unsigned short col,x,y;
  790.  LINE *curr;
  791.  char edit_fname[MAX_FILE_NAME];
  792.  int rc;
  793.  long true_line;
  794. /*--------------------------- processing ------------------------------*/
  795. #ifdef TRACE
  796.  trace_function("commsos.c: Sos_edit");
  797. #endif
  798. /*---------------------------------------------------------------------*/
  799. /* If the current file is not the special DIR.DIR file exit.           */
  800. /*---------------------------------------------------------------------*/
  801.  if (CURRENT_FILE->pseudo_file != PSEUDO_DIR)
  802.    {
  803. #ifdef TRACE
  804.     trace_return();
  805. #endif
  806.     return(RC_INVALID_ENVIRON);
  807.    }
  808. /*---------------------------------------------------------------------*/
  809. /* Determine which line contains a vaild file to edit. TOF and EOF are */
  810. /* invalid positions.                                                  */
  811. /*---------------------------------------------------------------------*/
  812.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  813.    {
  814.     if (CURRENT_TOF || CURRENT_BOF)
  815.       {
  816. #ifdef TRACE
  817.        trace_return();
  818. #endif
  819.        return(RC_INVALID_ENVIRON);
  820.       }
  821.     true_line = CURRENT_VIEW->current_line;
  822.    }
  823.  else
  824.    {
  825.     getyx(CURRENT_WINDOW,y,x);
  826.     if (FOCUS_TOF || FOCUS_BOF)
  827.       {
  828. #ifdef TRACE
  829.        trace_return();
  830. #endif
  831.        return(RC_INVALID_ENVIRON);
  832.       }
  833.     true_line = CURRENT_VIEW->focus_line;
  834.    }
  835. /*---------------------------------------------------------------------*/
  836. /* Find the current LINE pointer for the focus_line.                   */
  837. /*---------------------------------------------------------------------*/
  838. #ifdef USE_VOID
  839.  curr = (LINE *)ll_find((void *)CURRENT_FILE->first_line,true_line);
  840. #else
  841.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  842. #endif
  843. /*---------------------------------------------------------------------*/
  844.  post_process_line(CURRENT_VIEW->focus_line);
  845. /*---------------------------------------------------------------------*/
  846. /* Validate that the supplied file is valid.                           */
  847. /*---------------------------------------------------------------------*/
  848.  strcpy(edit_fname,dir_path);
  849.  strcat(edit_fname,curr->line+file_start);
  850.  if ((rc = splitpath(edit_fname)) != RC_OK)
  851.    {
  852.     display_error(10,temp_cmd);
  853. #ifdef TRACE
  854.     trace_return();
  855. #endif
  856.     return(rc);
  857.    }
  858. /*---------------------------------------------------------------------*/
  859. /* Edit the file.                                                      */
  860. /*---------------------------------------------------------------------*/
  861.  strcpy(edit_fname,sp_path);
  862.  strcat(edit_fname,sp_fname);
  863.  rc = Xedit(edit_fname);
  864. #ifdef TRACE
  865.  trace_return();
  866. #endif
  867.  return(rc);
  868. }
  869. /*man-start*********************************************************************
  870. COMMAND
  871.      SOS ENDChar - move cursor to end/start of focus line
  872.  
  873. SYNTAX
  874.      ** effective only if bound to a key **
  875.  
  876. DESCRIPTION
  877.      The SOS ENDCHAR command moves the cursor to the first character
  878.      displayed in the current window, if the cursor is after the last
  879.      character displayed in the current window, or to the position after
  880.      the last character displayed in the current window, if the cursor is
  881.      anywhere else.
  882.  
  883. COMPATIBILITY
  884.      XEDIT: N/A
  885.      KEDIT: Compatible. See below.
  886.      The possible combinations of VERIFY etc. make mimicing KEDIT very
  887.      difficult. The command is, on the surface, compatible.
  888.  
  889. STATUS
  890.      incomplete-problem determining exactly where the cursor should go
  891.      when a verify end is in place and we are going to the end of line
  892. **man-end**********************************************************************/
  893. #ifdef PROTO
  894. int Sos_endchar(char *params)
  895. #else
  896. int Sos_endchar(params)
  897. char *params;
  898. #endif
  899. /***********************************************************************/
  900. {
  901. /*--------------------------- local data ------------------------------*/
  902.  register short i;
  903.  unsigned short col,x,y,line_col;
  904. /*--------------------------- processing ------------------------------*/
  905. #ifdef TRACE
  906.  trace_function("commsos.c: Sos_endchar");
  907. #endif
  908.  getyx(CURRENT_WINDOW,y,x);
  909.  switch(CURRENT_VIEW->current_window)
  910.    {
  911.     case WINDOW_PREFIX:
  912. #ifdef TRACE
  913.          trace_return();
  914. #endif
  915.          return(RC_INVALID_ENVIRON);
  916.          break;
  917.     case WINDOW_COMMAND:
  918.          if (x >= cmd_rec_len)
  919.             wmove(CURRENT_WINDOW,y,0);
  920.          else
  921.             wmove(CURRENT_WINDOW,y,cmd_rec_len);
  922. #ifdef TRACE
  923.          trace_return();
  924. #endif
  925.          return(RC_OK);
  926.          break;
  927.     default:
  928.          break;
  929.    }
  930. /*---------------------------------------------------------------------*/
  931. /* Processing from here is for main window only.                       */
  932. /*---------------------------------------------------------------------*/
  933.  line_col = x + CURRENT_VIEW->verify_col;
  934.  if (line_col > min(rec_len,CURRENT_VIEW->verify_end))
  935.    {
  936.     CURRENT_VIEW->verify_col = max(CURRENT_VIEW->verify_start,1);
  937.     show_page();
  938.     wmove(CURRENT_WINDOW,y,0);
  939.    }
  940.  else
  941.    {
  942.     if (rec_len < CURRENT_SCREEN.cols)
  943.       {
  944.        x = min(rec_len-(CURRENT_VIEW->verify_col-1),CURRENT_VIEW->verify_end);
  945.        wmove(CURRENT_WINDOW,y,x);
  946.       }
  947.     else
  948.       {
  949.        x = CURRENT_SCREEN.cols / 2;
  950.        CURRENT_VIEW->verify_col = rec_len-x+1;
  951.        show_page();
  952.        wmove(CURRENT_WINDOW,y,x);
  953.       }
  954.    }
  955. #ifdef TRACE
  956.  trace_return();
  957. #endif
  958.  return(RC_OK);
  959. }
  960. /*man-start*********************************************************************
  961. COMMAND
  962.      SOS EXecute - move cursor to command line and execute command
  963.  
  964. SYNTAX
  965.      ** effective only if bound to a key **
  966.  
  967. DESCRIPTION
  968.      The SOS EXECUTE command moves the cursor to the command line
  969.      and executes any command that is on the command line.
  970.  
  971. COMPATIBILITY
  972.      XEDIT: N/A
  973.      KEDIT: Compatible
  974.  
  975. STATUS
  976.      Complete...but because of potential infinite recursion, this function
  977.      has been suspended.
  978. **man-end**********************************************************************/
  979. #ifdef PROTO
  980. int Sos_execute(char *params)
  981. #else
  982. int Sos_execute(params)
  983. char *params;
  984. #endif
  985. /***********************************************************************/
  986. {
  987. /*--------------------------- local data ------------------------------*/
  988.  int rc=RC_OK;
  989. /*--------------------------- processing ------------------------------*/
  990. #ifdef TRACE
  991.  trace_function("commsos.c: Sos_execute");
  992. #endif
  993.  
  994. #ifdef TRACE
  995.  trace_return();
  996. #endif
  997.  return(RC_OK);
  998.  
  999.  
  1000.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  1001.     rc = Tabcmd("");
  1002.  if (rc == RC_OK)
  1003.     rc = Enter("");
  1004.  
  1005. #ifdef TRACE
  1006.  trace_return();
  1007. #endif
  1008.  return(rc);
  1009. }
  1010. /*man-start*********************************************************************
  1011. COMMAND
  1012.      SOS MAKECURR - make focus line the current line
  1013.  
  1014. SYNTAX
  1015.      ** effective only if bound to a key **
  1016.  
  1017. DESCRIPTION
  1018.      The SOS MAKECURR command set the current line to the current focus
  1019.      line.
  1020.  
  1021. COMPATIBILITY
  1022.      XEDIT: N/A
  1023.      KEDIT: Compatible.
  1024.  
  1025. SEE ALSO
  1026.  
  1027. STATUS
  1028.      Complete
  1029. **man-end**********************************************************************/
  1030. #ifdef PROTO
  1031. int Sos_makecurr(char *params)
  1032. #else
  1033. int Sos_makecurr(params)
  1034. char *params;
  1035. #endif
  1036. /***********************************************************************/
  1037. {
  1038. /*--------------------------- local data ------------------------------*/
  1039.  int rc;
  1040. /*--------------------------- processing ------------------------------*/
  1041. #ifdef TRACE
  1042.  trace_function("commsos.c: Sos_makecurr");
  1043. #endif
  1044.  rc = execute_makecurr(CURRENT_VIEW->focus_line);
  1045. #ifdef TRACE
  1046.  trace_return();
  1047. #endif
  1048.  return(rc);
  1049. }
  1050. /*man-start*********************************************************************
  1051. COMMAND
  1052.      SOS TABf - move cursor to next tab stop
  1053.  
  1054. SYNTAX
  1055.      ** effective only if bound to a key **
  1056.  
  1057. DESCRIPTION
  1058.      The SOS TABF command causes the cursor to move to the next tab column
  1059.      as set by the TABS command. (The default is 8).
  1060.      If the resulting column is beyond the right hand edge of the main
  1061.      window, the window will scroll half a window.
  1062.  
  1063. COMPATIBILITY
  1064.      XEDIT: Does not allow arguments.
  1065.      KEDIT: Compatible. See below.
  1066.      Does not line tab to next line if after the right hand tab column.
  1067.  
  1068. SEE ALSO
  1069.      tabs
  1070.  
  1071. STATUS
  1072.      Complete.
  1073. **man-end**********************************************************************/
  1074. #ifdef PROTO
  1075. int Sos_tabf(char *params)
  1076. #else
  1077. int Sos_tabf(params)
  1078. char *params;
  1079. #endif
  1080. /***********************************************************************/
  1081. {
  1082. extern char tabkey_insert,tabkey_overwrite;
  1083. /*--------------------------- local data ------------------------------*/
  1084.  unsigned short x,y,num_cols,next_tab_col;
  1085. /*--------------------------- processing ------------------------------*/
  1086. #ifdef TRACE
  1087.  trace_function("commsos.c: Sos_tabf");
  1088. #endif
  1089. /*---------------------------------------------------------------------*/
  1090. /* If the actual tab character is to be display then exit so that      */
  1091. /* editor() can process it as a raw key.                               */
  1092. /*---------------------------------------------------------------------*/
  1093.  if (mode_insert && tabkey_insert == 'C')
  1094.    {
  1095. #ifdef TRACE
  1096.     trace_return();
  1097. #endif
  1098.     return(RAW_KEY);
  1099.    }
  1100.  if (!mode_insert && tabkey_overwrite == 'C')
  1101.    {
  1102. #ifdef TRACE
  1103.     trace_return();
  1104. #endif
  1105.     return(RAW_KEY);
  1106.    }
  1107.  
  1108.  getyx(CURRENT_WINDOW,y,x);
  1109. /*---------------------------------------------------------------------*/
  1110. /* First determine the number of characters to move to the right from  */
  1111. /* the current column.                                                 */
  1112. /*---------------------------------------------------------------------*/
  1113.  num_cols = (CURRENT_VIEW->tabs) -
  1114.             ((x + CURRENT_VIEW->verify_col) % CURRENT_VIEW->tabs);
  1115.  next_tab_col = x + CURRENT_VIEW->verify_col + num_cols;
  1116. /*---------------------------------------------------------------------*/
  1117. /* Check for going past end of line - max_line_length                  */
  1118. /*---------------------------------------------------------------------*/
  1119.  if (CURRENT_VIEW->verify_col+x+num_cols > max_line_length)
  1120.    {
  1121. #ifdef TRACE
  1122.     trace_return();
  1123. #endif
  1124.     return(RC_TRUNCATED);
  1125.    }
  1126. /*---------------------------------------------------------------------*/
  1127. /* For all windows, if the new cursor position does not exceed the     */
  1128. /* right edge, move there.                                             */
  1129. /*---------------------------------------------------------------------*/
  1130.  if (x+num_cols <= CURRENT_SCREEN.cols-1)
  1131.    {
  1132.     wmove(CURRENT_WINDOW,y,x+num_cols);
  1133. #ifdef TRACE
  1134.     trace_return();
  1135. #endif
  1136.     return(RC_OK);
  1137.    }
  1138. /*---------------------------------------------------------------------*/
  1139. /* For MAIN window, if the new cursor position exceeds the right edge  */
  1140. /* scroll the window half the width of the main window.                */
  1141. /*---------------------------------------------------------------------*/
  1142.  if (CURRENT_VIEW->current_window == WINDOW_MAIN)
  1143.     if (x+num_cols > CURRENT_SCREEN.cols-1)
  1144.       {
  1145.        x = CURRENT_SCREEN.cols / 2;
  1146.        CURRENT_VIEW->verify_col += x;
  1147.        show_page();
  1148.        wmove(CURRENT_WINDOW,y,(next_tab_col-CURRENT_VIEW->verify_col));
  1149. /*       wmove(CURRENT_WINDOW,y,(x+num_cols)-1);*/
  1150.       }
  1151. #ifdef TRACE
  1152.  trace_return();
  1153. #endif
  1154.  return(RC_OK);
  1155. }
  1156. /*man-start*********************************************************************
  1157. COMMAND
  1158.      SOS TABWORDB - move cursor to beginning of previous word
  1159.  
  1160. SYNTAX
  1161.      ** effective only if bound to a key **
  1162.  
  1163. DESCRIPTION
  1164.      The SOS TABWORDB command causes the cursor to move to the first character
  1165.      of the word to the left or to the start of the line if no more
  1166.      words precede.
  1167.      If the resulting column is beyond the left hand edge of the main
  1168.      window, the window will scroll half a window.
  1169.  
  1170. COMPATIBILITY
  1171.      XEDIT: N/A
  1172.      KEDIT: Compatible.
  1173.  
  1174. SEE ALSO
  1175.      SOS TABWORDF
  1176.  
  1177. STATUS
  1178.      Complete.
  1179. **man-end**********************************************************************/
  1180. #ifdef PROTO
  1181. int Sos_tabwordb(char *params)
  1182. #else
  1183. int Sos_tabwordb(params)
  1184. char *params;
  1185. #endif
  1186. /***********************************************************************/
  1187. {
  1188. /*--------------------------- local data ------------------------------*/
  1189.  unsigned short x,y,temp_rec_len;
  1190.  short start_word_col;
  1191.  unsigned short word_break;
  1192.  char *temp_rec;
  1193.  register short i;
  1194.  short num_cols,col_pos,col,left_col;
  1195. /*--------------------------- processing ------------------------------*/
  1196. #ifdef TRACE
  1197.  trace_function("commsos.c: Sos_tabwordb");
  1198. #endif
  1199. /*---------------------------------------------------------------------*/
  1200. /* This function is not applicable to the PREFIX window.               */
  1201. /*---------------------------------------------------------------------*/
  1202.  getyx(CURRENT_WINDOW,y,x);
  1203.  switch(CURRENT_VIEW->current_window)
  1204.    {
  1205.     case WINDOW_PREFIX:
  1206.          display_error(38,(char *)"");
  1207. #ifdef TRACE
  1208.          trace_return();
  1209. #endif
  1210.          return(RC_INVALID_ENVIRON);
  1211.          break;
  1212.     case WINDOW_MAIN:
  1213.          temp_rec = rec;
  1214.          temp_rec_len = rec_len;
  1215.          left_col = CURRENT_VIEW->verify_col-1;
  1216.          break;
  1217.     case WINDOW_COMMAND:
  1218.          temp_rec = cmd_rec;
  1219.          temp_rec_len = cmd_rec_len;
  1220.          left_col = 0;
  1221.          break;
  1222.    }
  1223. /*---------------------------------------------------------------------*/
  1224. /* Determine the start of the prior word, or go to the start of the    */
  1225. /* line if already at or before beginning of prior word.               */
  1226. /*---------------------------------------------------------------------*/
  1227.  word_break = 0;
  1228.  start_word_col = (-1);
  1229.  for (i=left_col+x;i>0;i--)
  1230.    {
  1231.     switch(word_break)
  1232.       {
  1233.        case 0:  /* still in current word */
  1234.             if (*(temp_rec+i) == ' ')
  1235.                word_break++;
  1236.             break;
  1237.        case 1:  /* in first blank space */
  1238.             if (*(temp_rec+i) != ' ')
  1239.                word_break++;
  1240.             break;
  1241.        case 2:  /* in previous word */
  1242.             if (*(temp_rec+i) == ' ')
  1243.               {
  1244.                start_word_col = i+1;
  1245.                word_break++;
  1246.               }
  1247.             break;
  1248.        default: /* should not get here */
  1249.             break;
  1250.       }
  1251.     if (word_break == 3)
  1252.        break;
  1253.    }
  1254.  if (start_word_col == (-1))
  1255.     start_word_col = 0;
  1256.  num_cols = (x + left_col) - start_word_col;
  1257. /*---------------------------------------------------------------------*/
  1258. /* For all windows, if the new cursor position is not less than the    */
  1259. /* left edge,  move there.                                             */
  1260. /* If in command window, this should always be true.                   */
  1261. /*---------------------------------------------------------------------*/
  1262.  col_pos = x;
  1263.  if (col_pos-num_cols >= 0)
  1264.    {
  1265.     wmove(CURRENT_WINDOW,y,x-num_cols);
  1266. #ifdef TRACE
  1267.     trace_return();
  1268. #endif
  1269.     return(RC_OK);
  1270.    }
  1271. /*---------------------------------------------------------------------*/
  1272. /* For MAIN window, if the new cursor position exceeds the right edge  */
  1273. /* scroll the window making the cursor appear in the window.           */
  1274. /*---------------------------------------------------------------------*/
  1275.  x = CURRENT_SCREEN.cols / 2;
  1276.  CURRENT_VIEW->verify_col = max(1,start_word_col - (short)x + 2);
  1277.  start_word_col = (CURRENT_VIEW->verify_col == 1) ? start_word_col : x - 1;
  1278.  wmove(CURRENT_WINDOW,y,start_word_col);
  1279.  show_page();
  1280. #ifdef TRACE
  1281.  trace_return();
  1282. #endif
  1283.  return(RC_OK);
  1284. }
  1285. /*man-start*********************************************************************
  1286. COMMAND
  1287.      SOS TABWORDf - move cursor to start of next word
  1288.  
  1289. SYNTAX
  1290.      ** effective only if bound to a key **
  1291.  
  1292. DESCRIPTION
  1293.      The SOS TABWORDF command causes the cursor to move to the first character
  1294.      of the next word to the right or to the end of the line if no more
  1295.      words follow.
  1296.      If the resulting column is beyond the right hand edge of the main
  1297.      window, the window will scroll half a window.
  1298.  
  1299. COMPATIBILITY
  1300.      XEDIT: N/A
  1301.      KEDIT: Compatible.
  1302.  
  1303. SEE ALSO
  1304.      SOS TABWORDB
  1305.  
  1306. STATUS
  1307.      Complete.
  1308. **man-end**********************************************************************/
  1309. #ifdef PROTO
  1310. int Sos_tabwordf(char *params)
  1311. #else
  1312. int Sos_tabwordf(params)
  1313. char *params;
  1314. #endif
  1315. /***********************************************************************/
  1316. {
  1317. /*--------------------------- local data ------------------------------*/
  1318.  unsigned short x,y,temp_rec_len,num_cols;
  1319.  short start_word_col,left_col;
  1320.  bool word_break;
  1321.  char *temp_rec;
  1322.  register short i;
  1323. /*--------------------------- processing ------------------------------*/
  1324. #ifdef TRACE
  1325.  trace_function("commsos.c: Sos_tabwordf");
  1326. #endif
  1327. /*---------------------------------------------------------------------*/
  1328. /* This function is not applicable to the PREFIX window.               */
  1329. /*---------------------------------------------------------------------*/
  1330.  getyx(CURRENT_WINDOW,y,x);
  1331.  switch(CURRENT_VIEW->current_window)
  1332.    {
  1333.     case WINDOW_PREFIX:
  1334.          display_error(38,(char *)"");
  1335. #ifdef TRACE
  1336.          trace_return();
  1337. #endif
  1338.          return(RC_INVALID_ENVIRON);
  1339.          break;
  1340.     case WINDOW_MAIN:
  1341.          temp_rec = rec;
  1342.          temp_rec_len = rec_len;
  1343.          left_col = CURRENT_VIEW->verify_col-1;
  1344.          break;
  1345.     case WINDOW_COMMAND:
  1346.          temp_rec = cmd_rec;
  1347.          temp_rec_len = cmd_rec_len;
  1348.          left_col = 0;
  1349.          break;
  1350.    }
  1351. /*---------------------------------------------------------------------*/
  1352. /* If we are after the last column of the line, then just ignore the   */
  1353. /* command and leave the cursor where it is.                           */
  1354. /*---------------------------------------------------------------------*/
  1355.  if ((x + left_col) > temp_rec_len)
  1356.    {
  1357. #ifdef TRACE
  1358.     trace_return();
  1359. #endif
  1360.     return(RC_OK);
  1361.    }
  1362. /*---------------------------------------------------------------------*/
  1363. /* Determine the start of the next word, or go to the end of the line  */
  1364. /* if already at or past beginning of last word.                       */
  1365. /*---------------------------------------------------------------------*/
  1366.  word_break = FALSE;
  1367.  start_word_col = (-1);
  1368.  for (i=left_col+x;i<temp_rec_len;i++)
  1369.    {
  1370.     if (*(temp_rec+i) == ' ')
  1371.        word_break = TRUE;
  1372.     else
  1373.       {
  1374.        if (word_break)
  1375.          {
  1376.           start_word_col = i;
  1377.           break;
  1378.          }
  1379.       }
  1380.    }
  1381.  if (start_word_col == (-1))
  1382.     start_word_col = temp_rec_len;
  1383.  num_cols =  start_word_col - (x + CURRENT_VIEW->verify_col -1);
  1384. /*---------------------------------------------------------------------*/
  1385. /* For all windows, if the new cursor position does not exceed the     */
  1386. /* right edge, move there.                                             */
  1387. /* If in command window, this should always be true.                   */
  1388. /*---------------------------------------------------------------------*/
  1389.  if (x+num_cols <= CURRENT_SCREEN.cols-1
  1390.  || CURRENT_VIEW->current_window == WINDOW_COMMAND)
  1391.    {
  1392.     wmove(CURRENT_WINDOW,y,x+num_cols);
  1393. #ifdef TRACE
  1394.     trace_return();
  1395. #endif
  1396.     return(RC_OK);
  1397.    }
  1398. /*---------------------------------------------------------------------*/
  1399. /* For MAIN window, if the new cursor position exceeds the right edge  */
  1400. /* scroll the window half the width of the main window.                */
  1401. /*---------------------------------------------------------------------*/
  1402.  x = CURRENT_SCREEN.cols / 2;
  1403.  CURRENT_VIEW->verify_col = max(1,start_word_col - x + 2);
  1404.  start_word_col = (CURRENT_VIEW->verify_col == 1) ? start_word_col : x - 1;
  1405.  wmove(CURRENT_WINDOW,y,start_word_col);
  1406.  show_page();
  1407. #ifdef TRACE
  1408.  trace_return();
  1409. #endif
  1410.  return(RC_OK);
  1411. }
  1412. /*man-start*********************************************************************
  1413. COMMAND
  1414.      SOS UNDO - undo changes to the current line
  1415.  
  1416. SYNTAX
  1417.      ** effective only if bound to a key **
  1418.  
  1419. DESCRIPTION
  1420.      The SOS UNDO command causes the contents of the focus line (or the
  1421.      command line) to be reset to the contents before the cursor was
  1422.      positioned there.
  1423.  
  1424. COMPATIBILITY
  1425.      XEDIT: N/A
  1426.      KEDIT: Compatible. See below.
  1427.      Basically compatible. Doesn't restore the cursor to the original
  1428.      column position.
  1429.  
  1430. STATUS
  1431.      Complete.
  1432. **man-end**********************************************************************/
  1433. #ifdef PROTO
  1434. int Sos_undo(char *params)
  1435. #else
  1436. int Sos_undo(params)
  1437. char *params;
  1438. #endif
  1439. /***********************************************************************/
  1440. {
  1441. /*--------------------------- local data ------------------------------*/
  1442.  unsigned short x,y,temp_rec_len,num_cols;
  1443.  short start_word_col;
  1444.  bool word_break;
  1445.  char *temp_rec;
  1446.  register short i;
  1447. /*--------------------------- processing ------------------------------*/
  1448. #ifdef TRACE
  1449.  trace_function("commsos.c: Sos_undo");
  1450. #endif
  1451.  switch (CURRENT_VIEW->current_window)
  1452.    {
  1453.     case WINDOW_MAIN:
  1454.          pre_process_line(CURRENT_VIEW->focus_line);
  1455.          show_page();
  1456.          break;
  1457.     case WINDOW_COMMAND:
  1458.          memset(cmd_rec,' ',COLS);
  1459.          cmd_rec_len = 0;
  1460.          wmove(CURRENT_WINDOW,0,0);
  1461.          my_wclrtoeol(CURRENT_WINDOW);
  1462.          break;
  1463.     case WINDOW_PREFIX:
  1464.          prefix_changed = TRUE;
  1465.          memset(pre_rec,' ',PREFIX_WIDTH);
  1466.          pre_rec_len = 0;
  1467.          getyx(CURRENT_WINDOW,y,x);
  1468.          wmove(CURRENT_WINDOW,y,0);
  1469.          my_wclrtoeol(CURRENT_WINDOW);
  1470.          break;
  1471.     default:
  1472.          break;
  1473.    }
  1474. #ifdef TRACE
  1475.  trace_return();
  1476. #endif
  1477.  return(RC_OK);
  1478. }
  1479.